﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessLayer;
using BusinessLayer.Tables;

public partial class Admin_FiyatTanim : ChildPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        imgbtnKaydetKapat.Attributes.Add("onclick", "return Kontrol();");
        imgbtnKaydet.Attributes.Add("onclick", "return Kontrol();");
        imgbtnSil.Attributes.Add("onclick", "return SilKontrol();");
        if (!IsPostBack)
        {
            if (Request.QueryString.Count > 0)
            {
                string id = Request.QueryString["id"];
                KayitBul(id);
            }
        }
    }
    #region Function
    private void CreateArea()
    {
        foreach (System.Web.UI.Control c in pnlControls.Controls)
        {
            if (c is CrmControls.CrmTextBox)
            {
                CrmControls.CrmTextBox txt = c as CrmControls.CrmTextBox;
                txt.Text = "";
            }
            if (c is CrmControls.CrmCheckBox)
            {
                CrmControls.CrmCheckBox chk = c as CrmControls.CrmCheckBox;
                chk.Checked = false;
            }
        }
    }
    public void KayitBul(string id)
    {
        Db_FiyatTanim fyt = new Db_FiyatTanim();
        fyt.FiyatKod = Int16.Parse(id);
        fyt.KayitBul();
        if (fyt.FiyatKod != null)
        {
            txtfytadi.Text = fyt.FiyatAdi;
            txtfytkod.Text = fyt.FiyatKod.ToString();
            if (fyt.FiyatKdvDahil == true)
                chk_Fyt_Kdv_Dahilmi.Checked = true;
            else
                chk_Fyt_Kdv_Dahilmi.Checked = false;
        }
    }
    private void Kaydet()
    {
        Db_FiyatTanim fyt = new Db_FiyatTanim();
        if (txtfytkod.Text != "" && txtfytadi.Text != "")
        {
            fyt.Create_Date = DateTime.Now;
            fyt.Create_User = 1;
            fyt.FiyatAdi = txtfytadi.Text;
            fyt.FiyatKod = Int16.Parse(txtfytkod.Text);
            if (chk_Fyt_Kdv_Dahilmi.Checked)
                fyt.FiyatKdvDahil = true;
            else
                fyt.FiyatKdvDahil = false;
            fyt.Hidden = true;
            fyt.Locked = true;
            fyt.Update_Date = DateTime.Now;
            fyt.Update_User = 1;
            fyt.Save();
            CreateArea();
        }
        else
        {
            if (txtfytadi.Text == "")
                CrmControls.MessageBx.Show("Lütfen Fiyat Adını Boş Bırakmayın!..");
            if (txtfytkod.Text == "")
                CrmControls.MessageBx.Show("Lütfen Fiyat Kodunu Boş Bırakmayın!..");
        }
    }
    #endregion
    protected void imgbtnKaydet_Click(object sender, ImageClickEventArgs e)
    {
        Kaydet();
        this.ClientScript.RegisterStartupScript(typeof(Page), "Tazele", "Refresh();", true);
    }
    protected void imgbtnKaydetKapat_Click(object sender, ImageClickEventArgs e)
    {
        Kaydet();
        this.Page.ClientScript.RegisterStartupScript(typeof(Page), "test", "PageClose();", true);
    }
    protected void imgbtnSil_Click(object sender, ImageClickEventArgs e)
    {
        Db_FiyatTanim fyt = new Db_FiyatTanim();
        fyt.FiyatKod = Int16.Parse(txtfytkod.Text);
        if (txtfytkod.Text != "")
        {
            fyt.KayitSil();
            CreateArea();
        }
        else
            CrmControls.MessageBx.Show("Lütfen Fiyat Kodunu Boş Bırakmayın!..");
        this.ClientScript.RegisterStartupScript(typeof(Page), "Yenile", "Refresh();", true);
    }

    protected void imgNewREcord_Click(object sender, ImageClickEventArgs e)
    {
        CreateArea();
    }
}
